package com.movitech.mobile.cz.base.purchase.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.google.common.collect.Maps;
import com.movitech.mobile.cz.base.common.util.CommonConstants;
import com.movitech.mobile.cz.base.modules.config.PurchaseCommonEnum;
import com.movitech.mobile.cz.base.purchase.entity.WFlowFormAddendumReferers;
import com.movitech.mobile.cz.base.purchase.entity.ext.ExtWFlowFormAddendumReferers;
import com.movitech.mobile.cz.base.purchase.mapper.WFlowFormAddendumReferersMapper;
import com.movitech.mobile.cz.base.purchase.mapper.ext.ExtWFlowFormAddendumReferersMapper;
import com.movitech.mobile.cz.base.purchase.service.WFlowFormAddendumReferersService;
import com.movitech.mobile.cz.base.sys.entity.ext.ExtSAttachment;
import com.movitech.mobile.cz.base.util.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 流程表单-答疑补遗-补遗 服务实现类
 * </p>
 *
 * @author Movitech Mobile
 * @since 2018-03-15
 */
@Service
public class WFlowFormAddendumReferersServiceImpl extends ServiceImpl<WFlowFormAddendumReferersMapper, WFlowFormAddendumReferers> implements WFlowFormAddendumReferersService {
   @Autowired
   private ExtWFlowFormAddendumReferersMapper  extWFlowFormAddendumReferersMapper;
    @Override
    public boolean deleteById(String id) {
        WFlowFormAddendumReferers wFlowFormAddendumReferers= new WFlowFormAddendumReferers();
        wFlowFormAddendumReferers.setId(id);
        wFlowFormAddendumReferers.setBaseFeilds(UserUtils.getCurrentUserId(), null, CommonConstants.DEL_FLAG_DELETE, false);
        return updateById(wFlowFormAddendumReferers);
    }

    @Override
    public boolean updateCountResultById(String id,Integer countResult) {
        WFlowFormAddendumReferers wFlowFormAddendumReferers = new WFlowFormAddendumReferers();
        wFlowFormAddendumReferers.setId(id);
        wFlowFormAddendumReferers.setCountSignResult(countResult);
        wFlowFormAddendumReferers.setAddendumStatus(PurchaseCommonEnum.ADDENDUM_STATUS_START.getCode());
        return updateById(wFlowFormAddendumReferers);
    }

    @Override
    public List<ExtWFlowFormAddendumReferers> findExtByFormId(String formId) {
        return extWFlowFormAddendumReferersMapper.findByFormId(formId);
    }

    @Override
    public List<ExtSAttachment> findSendedAttachment(String formId) {
        Map<String,Object> param = Maps.newHashMapWithExpectedSize(2);
        param.put("formId",formId);
        param.put("status",PurchaseCommonEnum.ASK_FILE_SEND_END.getCode());
        param.put("userId",UserUtils.getOuterCurrentUserVO().getSuppliersId());
        return extWFlowFormAddendumReferersMapper.findSendedAttachment(param);
    }

    @Override
    public WFlowFormAddendumReferers addByFormId(String formId) {
        WFlowFormAddendumReferers wFlowFormAddendumReferers= new WFlowFormAddendumReferers();
        wFlowFormAddendumReferers.setBaseFeilds(UserUtils.getCurrentUserId(),"", CommonConstants.DEL_FLAG_NORMAL,true);
        wFlowFormAddendumReferers.setFlowFormId(formId);
        wFlowFormAddendumReferers.setAddendumStatus(PurchaseCommonEnum.ADDENDUM_STATUS_START.getCode());
        insert(wFlowFormAddendumReferers);
        return wFlowFormAddendumReferers;
    }
}
